<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>后台登录</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" type="text/css" href="jquery-easyui-1.4.3/themes/black/easyui.css">
	<link rel="stylesheet" type="text/css" href="jquery-easyui-1.4.3/themes/icon.css">
	<script type="text/javascript" src="jquery-easyui-1.4.3/jquery.min.js"></script>
	<script type="text/javascript" src="jquery-easyui-1.4.3/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="jquery-easyui-1.4.3/locale/easyui-lang-zh_CN.js"></script>
	<style>
		#safecode:hover{
			cursor:pointer;
		}
		#refrashcode{
			text-decoration: none;
		}
	</style>

	<script>
		function login(){
			var type=$("#dlg input:radio:checked").val()//身份选择
			var uname=$("#uname").val();
			var pwd=$("#pwd").val();
			var valcode=$("#valcode").val();
			if(uname==""&&pwd==""&&valcode==""){
				 showinfobox("登录页必须填写完整");
			}else if(uname==""){
				//alert("uname");
				showinfobox("用户名不能为空")
			}else if(pwd==""){
				//alert("pwd");
				showinfobox("密码不能为空");
			}else if(valcode==""){
				//alert("valcode");
				showinfobox("验证码不能为空,请输入四位有效验证码");
			}else{
				if(type==1){
					$.ajax({
						type:"POST",
						url:"cust.action",
						data:$("#loginForm").serialize(),
						dataType:"JSON",
						 success:function(data){
							//alert("login");
							if(data.code==1){
								//成功
								location.href='backadmin/index.jsp';
							}else if(data.code==0){
								showinfobox(data.msg);
								recode();
							}else if(data.code=2){
								//拼接的fid在不取的时候对页面不造成影响
								location.href=data.msg+"&fid=0";
								//location.href=data.msg+"&fid=2";
							}
						 }
					});
				}else if(type==2){
					$.ajax({
						type:"POST",
						url:"customerService.action",
						data:$("#loginForm").serialize(),
						dataType:"JSON",
						 success:function(data){
							if(data.code==1){
								//成功
								location.href='customerService/index.jsp';
							}else if(data.code==0){
								showinfobox(data.msg);
								recode();
							}
						 }
					});
				}
			}
		}
		function recode(){
			$("#safecode").attr("src","code.action?t="+Math.random());
			$("#valcode").textbox("setValue","");
		}
		
		function showinfobox(string){
			$("#infomessage").stop(true,true);
			$("#infomessage p").html(string);
			$("#infomessage").slideDown('narmal').delay(3000).slideUp('fast');
		}
		
		
		$(function(){
			$("#loginForm input").bind({
				blur:function(){
					resetLoginButton();
				}
			})
			
		});
		
		var ButtonMark=1;//1 disabled=true;0 disabled=false
		//判断登陆按钮是否可以点击事件
		function resetLoginButton(){
			var isValid1 = $("#uname").validatebox('isValid');
			var isValid2 = $("#pwd").validatebox('isValid');
			var isValid3 = $("#valcode").validatebox('isValid');
			if(ButtonMark==1){
				if( isValid1  && isValid2  && isValid3 ){
					$("#dlg").dialog({
						buttons:[{
							text:'登陆',
							iconCls: 'icon-ok',
							disabled:false,
							handler:function(){
								login();
							}
						}]
					});
					ButtonMark=0;
				}
			}else if(ButtonMark==0){
				if( !isValid1 || !isValid2 || !isValid3 ){
					$("#dlg").dialog({
						buttons:[{
							text:'登陆',
							iconCls: 'icon-ok',
							disabled:true,
							handler:function(){
								login();
							}
						}]
					});
					ButtonMark=1;
				}
			}
		}
		//给登录按钮添加回车确定的快捷键
		function yhj_keyUp(e) {
	　　       　 	 var currKey=0,e=e||event;
	　　      　 	 currKey=e.keyCode||e.which||e.charCode;
	　　      　	　var keyName = String.fromCharCode(currKey);
	　　       　	 // alert("按键码: " + currKey + " 字符: " + keyName);
	　　       	//如果按下的键是回车键，   code=13 且，
	         if(currKey==13){
	        	 login();
	         }
　　       	}
　　      	 document.onkeyup = yhj_keyUp;
		
	</script>
  </head>
  
  <body style="margin:0px auto;background:url(images/yhj-bg.jpg);">
  
  	<img src="images/yhj_20150901105929.png" height="100" style="position:absolute;top:70px;left:540px;"/>
  
	<div id="dlg" class="easyui-dialog" title="后台登录" style="width:300px;height:350px;padding:15px;;top:200px;left:520px;"
			data-options="
				resizable:false,
				closable:false,
				draggable:false,
				modal:false,
				iconCls: 'icon-back',
				
				buttons: [{
					text:'登录',
					iconCls:'icon-ok',
					disabled:true,
					handler:function(){
						//alert('ok');
						//判断界面数据
						//showinfobox();
						login();
					}
				}]
			">
			<form name="loginForm" id="loginForm">
				<input type="hidden" name="op" value="backlogin"/>
				用户名：<input value="a" style="width:100%;height:24px;" class="easyui-textbox easyui-validatebox" data-options="required:true,iconCls:'icon-man',missingMessage:'请输入用户名'" type="text" id="uname" name="aname"/><br><br>
				密&nbsp;&nbsp;&nbsp;码：<input value="a" style="width:100%;height:24px;" type="password" id="pwd" class="easyui-textbox easyui-validatebox" data-options="required:true,iconCls:'icon-lock',missingMessage:'请输入密码'" name="apwd"/><br><br>
				验证码：<input style="width:100%;height:24px;" class="easyui-textbox easyui-validatebox" data-options="required:true,missingMessage:'请输入验证码',validType:'length[4,4]',prompt:'请输入四位验证码'" type="text" id="valcode" name="valcode"/><br><br>
				<p style="text-align:center;margin-top:0px;"><img id="safecode" style="border:1px solid black;" src="code.action" onClick="recode()" title="看不清请戳此刷新"/><a style="margin-left:10px;position:relative;top:-10px" id="refrashcode" href="javascript:recode()">点此刷新验证码</a></p>
			</form>
			<p style="text-align:center;margin-top:0px;"><input name="type" type="radio" checked="checked" value="1" />管理员 <input name="type" type="radio" value="2" />客服 </p>
	</div>	
	
	 <!-- 
		<div id="mm" class="easyui-menu" data-options="onClick:menuHandler" style="width:120px;">
		<div data-options="name:'new'">New</div>
		<div data-options="name:'save',iconCls:'icon-save'">Save</div>
		<div data-options="name:'print',iconCls:'icon-print'">Print</div>
		<div class="menu-sep"></div>
		<div data-options="name:'exit'">Exit</div>
	</div>
	<script>
		function menuHandler(item){
			alert(item.name);
		}
		$(function(){
			$(document).bind('contextmenu',function(e){
				e.preventDefault();
				$('#mm').menu('show', {
					left: e.pageX,
					top: e.pageY
				});
			});
		});
	</script>-->
	<div id="infomessage" style="position:absolute;bottom:0px; right:50px;display:none;">
	    <div id="p" class="easyui-panel" title="提示" 
	            style="width:200px;height:150px;padding:10px;background:#fafafa;"
	            data-options="iconCls:'icon-save'">
	        <p style="color:black;">显示提示信息</p>
	    </div>
	</div>
  </body>
</html>
